home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 March / Macworld (1998-03) (Disk 1).dmg / Shareware World / Utilities / Text Processing / Alpha / Tcl / Modes / HTML and CSS Modes / hctsmslMenu.tcl < prev    next >
Encoding:
Text File  |  1997-11-02  |  8.9 KB  |  260 lines  |  [TEXT/ALFA]

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #  HTML and CSS mode - tools for editing Cascading Style Sheets
  4.  # 
  5.  #  FILE: "hctsmslMenu.tcl"
  6.  #                                    created: 97-03-01 17.33.59 
  7.  #                                last update: 97-10-29 19.32.08 
  8.  #  Author: Johan Linde
  9.  #  E-mail: <jl@theophys.kth.se>
  10.  #     www: <http://bach.theophys.kth.se/~jl/Alpha.html>
  11.  #  
  12.  # Version: 2.0.3 and 1.0.3
  13.  # 
  14.  # Copyright 1996, 1997 by Johan Linde
  15.  #  
  16.  # This software may be used freely, and distributed freely, as long as the 
  17.  # receiver is not obligated in any way by receiving it.
  18.  #  
  19.  # If you make improvements to this file, please share them!
  20.  # 
  21.  # ###################################################################
  22.  ##
  23.  
  24. proc hctsmslMenu.tcl {} {}
  25.  
  26. # Variables defining submenus.
  27. set htmlStyleSub {{"" Style STYLE} {"" Span SPAN} "(-" {"" "Import…"} {"" Font} {"" Color}
  28.     {"" Background} {"" Text} {"" Margin}
  29.     {"" Padding} {"" Border} {"" "Border Width"} {"" "Border Style"}
  30.     {"" "Border Color"} {"" Size} {"" Float} 
  31.     {"" Clear} {"" Display} {"" "List Style"}}
  32.  
  33. set htmlHeadersSub {{"<B<O/1" "Header1/H1 no attr" H1}
  34.     {"<B<O/2" "Header2/H2 no attr" H2}
  35.     {"<B<O/3" "Header3/H3 no attr" H3}
  36.     {"<B<O/4" "Header4/H4 no attr" H4}
  37.     {"<B<O/5" "Header5/H5 no attr" H5}
  38.     {"<B<O/6" "Header6/H6 no attr" H6}}
  39.  
  40. set htmlBlocksSub {{"" "Insert Line Breaks/Remove Line Breaks"}
  41.     {"" "Insert Paragraphs"} "(-"
  42.     {"<U/b" "Paragraph/P no attr" P}
  43.     {"<U<O/b" "Division" DIV}
  44.     {"<B<O/Q" "Block Quote" BLOCKQUOTE} {"<B<O/S" "Address" ADDRESS}
  45.     {"<B<O/C" "Center" CENTER} {"<B<O/P" "Preformatted" PRE}
  46.     {"<B<O/X" "Multi Column" MULTICOL}
  47.     {"<B<O/Z" "Spacing" SPACER} "(-"
  48.     {"<O/b" "Line Break/BR no attr" BR}
  49.     {"<B<O/H" "Horizontal Rule/HR no attr" HR}
  50.     {"<B<O/B" "No Line Break" NOBR} {"<B<O/W" "Word Break" WBR}}
  51.  
  52. set htmlStylesSub {{"<B<I/F" Font FONT} {"<B<I/N" Basefont BASEFONT}
  53.     {"" Marquee MARQUEE} "(-" {"<B<I/B" Bold B}
  54.     {"<B<I/I" Italic I} {"<B<I/-" "Strike out" STRIKE} {"<B<I<O/-" Underlined U}
  55.     {"<B<I/." Superscript SUP} {"<B<I/," Subscript SUB} {"<B<I<O/." Bigger BIG}
  56.     {"<B<I<O/," Smaller SMALL} {"<B<I/T" Typewriter TT} {"<B<I/Z" Blinking BLINK}
  57.     "(-" {"<B<I/E" Emphasis EM} {"<B<I/S" Strong STRONG} {"<B<I/D" Definition DFN}
  58.     {"<B<I/C" Code CODE} {"<B<I/V" Variable VAR}    {"<B<I/X" Citation CITE} 
  59.     {"<B<I/K" Keyboard KBD} {"<B<I/P" Sample SAMP}}
  60.  
  61. set htmlLinksSub {{"<B<O/A" "Link or Anchor" A} {"<B<O/I" Image IMG}
  62.     {"" Object OBJECT} {"" Sound BGSOUND}}
  63.  
  64. set htmlPlug-insSub {{"<B<O/E" General EMBED} {"" LiveAudio EMBED}
  65.     {"" LiveVideo EMBED} {"" "QuickTime Movie" EMBED}
  66.     {"" "QuickTime VR" EMBED} {"" RealAudio EMBED} "(-" {"<B<O/N" "No Embed" NOEMBED}}
  67.  
  68. set htmlListsSub {{"" "Make List…"} "(-" {"<B<O/U" "Bulleted/UL no attr" UL}
  69.     {"<B<I/U" "New Bulleted Item"}
  70.     {"<B<O/O" "Numbered/OL no attr" OL}
  71.     {"<B<I/O" "New Numbered Item"} {"<B<O/D" "Directory" DIR}
  72.     {"<B<O/M" "Menu" MENU} {"<B<I/L" "New List Item" LI} "(-"
  73.     {"<B<U<O/D" "Discursive" DL} {"<B<I<O/L" "New Discursive Entry"}}
  74.  
  75. set htmlFormsSub {{"<B<U/F" Form FORM} "(-" {"<B<U/T" Text INPUT}
  76.     {"<B<U/B" Checkbox  INPUT} {"<B<U/N" Button INPUT}
  77.     {"<B<U/R" Radio INPUT} {"<B<U/S" Submit INPUT}
  78.     {"<B<U/C" Reset INPUT} {"<B<U/P" Password INPUT}
  79.     {"<B<U/H" Hidden INPUT} {"<B<U/I" Image INPUT}
  80.     {"<B<U/U" "File Upload" INPUT}
  81.     "(-" {"<B<U<I/S" Select SELECT} {"<B<U/O" Option OPTION}
  82.     {"<B<U<I/T" Textarea TEXTAREA} {"" "Key Generator" KEYGEN}}
  83.  
  84. set htmlTablesSub {{"" "Table Template…"} {"" "Tabs to Rows…/Rows to Tabs"} {"" "Import Table…"} "(-"
  85.     {"<U<O/T" Table TABLE} {"<U<O/R" "Row/TR no attr" TR}
  86.     {"<U<O/H" "Header/TH no attr" TH} {"<U<O/D" "Cell/TD no attr" TD}
  87.     {"<U<O/C" Caption CAPTION} "(-"
  88.     {"" Head THEAD} {"" Body TBODY} {"" Foot TFOOT}
  89.     "(-" {"" "Column Group" COLGROUP} {"" "Column" COL}}
  90.  
  91. set htmlFramesSub {{"<B<U<I/F" "New Doc. with Frames…"} "(-" {"<B<U<I/O" Frameset FRAMESET}
  92.     {"<B<U<I/R" Frame FRAME} {"" "Inline Frame" IFRAME}
  93.     {"<B<U<I/N" "No Frames" NOFRAMES}}
  94.  
  95. set htmlImageSub {{"" "Convert NCSA Map…"} {"" "Convert CERN Map…"} "(-" {"<B<U/M" Map MAP} 
  96.     {"<B<U/A" Area AREA}}
  97.  
  98. set htmlJavaSub {{"<U<I<O/J" Applet APPLET} {"<U<I<O/P" Parameter PARAM}
  99.     "(-" {"<U<I<O/S" Script SCRIPT} {"<U<I<O/N" "No Script" NOSCRIPT}}
  100.  
  101. set htmlLayersSub {{"" Layer LAYER} {"" "Inline Layer" ILAYER} {"" "No Layer" NOLAYER}}
  102.  
  103. set htmlOtherSub {{"<B<U<I/C" Comment} {"<B<U<I/B" Base BASE}
  104.     {"<B<U<I/I" Isindex ISINDEX}
  105.     {"<B<U<I/L" Link LINK} {"<B<U<I/M" Meta META} {"" "Comment Line"}}
  106.  
  107. set htmlSubMenus {HTML Browsers Packages Preferences
  108. {Style Sheets} Headers {Blocks and Dividers} Styles Links 
  109. Plug-ins Lists Forms Tables Frames {Image Maps} {Java and JavaScript} Layers Other}
  110.  
  111. # Index of which menu is the first with HTML elements.
  112. set htmlStartElements 4
  113.  
  114. # Returns a list defining a submenu.
  115. proc htmlBuildOneMenu {me} {
  116.     global htmlMenuKey
  117.     set me0 [lindex $me 0]
  118.     global html${me0}Sub
  119.     # CSS menu share with Style menu
  120.     if {$me0 == "CSS"} {set me0 Style}
  121.     set tmp ""
  122.     foreach it [set html[lindex $me 0]Sub] {
  123.         if {$it == "(-"} {lappend tmp $it; continue}
  124.         if {[info exists htmlMenuKey(${me0}/[lindex $it 1])]} {
  125.             set key $htmlMenuKey(${me0}/[lindex $it 1])
  126.         } else {
  127.             set key [lindex $it 0]
  128.         }
  129.         set it2 [split [lindex $it 1] /]
  130.         if {[llength $it2] == 1} {
  131.             lappend tmp "$key[lindex $it2 0]"
  132.         } elseif {$key != ""} {
  133.             lappend tmp "<S$key[lindex $it2 0]" "<S<I$key[lindex $it2 1]"
  134.         } else {
  135.             lappend tmp "<S$key[lindex $it2 1]" "<S$key[lindex $it2 0]"
  136.         }
  137.     }
  138.     return $tmp
  139. }
  140.  
  141. # Rebuilds a submenu.
  142. proc htmlRebuildOneMenu {me {deleteCache 0}} {
  143.     set meny [htmlBuildOneMenu [lindex $me 0]]
  144.     menu -M HTML -p htmlMenuItem -m -n $me $meny
  145.     if {[info commands "html[lindex $me 0]MenuExtra"] != ""} {
  146.         eval html[lindex $me 0]MenuExtra
  147.     }
  148.     if {$deleteCache} {
  149.         htmlDeleteCache "HTML menu cache"
  150.         htmlDeleteCache "HTML Utilities menu cache"
  151.     }
  152.     htmlDisMark
  153.     htmlUtilDisMark
  154. }
  155.  
  156. proc htmlReadMenuKeys {} {
  157.     global PREFS
  158.     if {[file exists "$PREFS:HTML:Menu key bindings"]} {
  159.         catch {uplevel #0 [list source "$PREFS:HTML:Menu key bindings"]}
  160.     }
  161. }
  162.  
  163. proc htmlWriteMenuKeys {} {
  164.     global PREFS htmlMenuKey
  165.     if {![info exists htmlMenuKey]} {return}
  166.     message "Saving custom key bindings…"
  167.     foreach m [array names htmlMenuKey] {
  168.         lappend txt "set htmlMenuKey(\[list $m\]) [list $htmlMenuKey($m)]"
  169.     }
  170.     if {![file exists $PREFS]} {mkdir $PREFS}
  171.     if {![file exists $PREFS:HTML]} {mkdir $PREFS:HTML}
  172.     set fid [open "$PREFS:HTML:Menu key bindings" w]
  173.     puts $fid [join $txt \n]
  174.     close $fid
  175.     unset htmlMenuKey
  176. }
  177.  
  178. #===============================================================================
  179. # Custom Key Bindings
  180. #===============================================================================
  181.  
  182. proc htmlKeyBindings {} {
  183.     global htmlSubMenus htmlUtilSubMenus htmlMenuKey
  184.     set ret ""
  185.     set rebuildHTML 0
  186.     set rebuildUtils 0
  187.     set rebuildCSS 0
  188.     set somethingModified 0
  189.     htmlReadMenuKeys
  190.     if {![catch {listpick -p "Choose a submenu to change key bindings in" [lsort [concat $htmlSubMenus $htmlUtilSubMenus]]} meny] && $meny != ""} {
  191.         htmlSetKeysInMenu $meny
  192.     }
  193.     if {$somethingModified} {htmlWriteMenuKeys}
  194.     if {$rebuildHTML} {htmlRebuildMenu "Rebuilding HTML menu…"; message "Done."}
  195.     if {$rebuildUtils} {htmlRebuildUtilsMenu "Rebuilding HTML Utilities menu…"; message "Done."}
  196.     if {$rebuildCSS} {cssRebuildMenu}
  197.     catch {unset htmlMenuKey}
  198. }
  199.  
  200.  
  201. # Redefine key bindings in one submenu.
  202. proc htmlSetKeysInMenu {meny} {
  203.     global htmlMenuKey htmlModeIsLoaded cssModeIsLoaded
  204.     
  205.     set meny0 [lindex $meny 0]
  206.     global html${meny0}Sub
  207.     # CSS menu share with Style menu
  208.     if {$meny0 == "CSS"} {set meny0 Style}
  209.     set items [set html[lindex $meny 0]Sub]
  210.     regsub -all {\"\(-\"} $items "" items
  211.     foreach it $items {
  212.         if {[info exists htmlMenuKey(${meny0}/[lindex $it 1])]} {
  213.             set tmpKeys([lindex $it 1]) $htmlMenuKey(${meny0}/[lindex $it 1])
  214.         } else {
  215.             set tmpKeys([lindex $it 1]) [lindex $it 0]
  216.         }
  217.         lappend items2 [list $tmpKeys([lindex $it 1]) [lindex $it 1]]
  218.     }
  219.     if {[eval dialog::adjustBindings [list $meny] newKeys modified 1 $items2] == "Cancel"} {return}
  220.  
  221.     # Save new key bindings
  222.     foreach it $modified {
  223.         set htmlMenuKey(${meny0}/$it) $newKeys($it)
  224.     }
  225.     if {[llength $modified]} {
  226.         htmlDeleteCache "CSS keybindings cache"
  227.         uplevel 1 {set somethingModified 1}
  228.         switch $meny {
  229.             HTML {uplevel 1 {set rebuildHTML 1}}
  230.             Utilities {uplevel 1 {set rebuildUtils 1}}
  231.             "Style Sheets" {
  232.                 # Rebuild both Style sheet menu and CSS menu
  233.                 htmlDeleteCache "CSS menu cache"
  234.                 htmlRebuildOneMenu "Style Sheets" 1
  235.                 if {[info exists cssModeIsLoaded]} {uplevel 1 {set rebuildCSS 1}}
  236.             }
  237.             CSS {
  238.                 # Rebuild both Style sheet menu and CSS menu
  239.                 if {[info exists htmlModeIsLoaded]} {
  240.                     htmlRebuildOneMenu "Style Sheets" 1
  241.                 } else {
  242.                     htmlDeleteCache "HTML menu cache"
  243.                 }
  244.                 uplevel 1 {set rebuildCSS 1}
  245.             }
  246.             default {
  247.                 htmlRebuildOneMenu $meny 1
  248.                 # Redefine key bindinds in CSS mode.
  249.                 if {[info exists cssModeIsLoaded]} {
  250.                     foreach k [array names newKeys] {
  251.                         lappend re [list $k $tmpKeys($k) $newKeys($k)]
  252.                         cssReBindKey $meny0 $re
  253.                     }
  254.                 }
  255.             }
  256.         }
  257.     }
  258. }
  259.  
  260.